using System;
using System.Collections.Generic;
using iPhOwa.Exchange.ContentClasses;
using iPhOwa.Exchange.Managers;

namespace iPhOwa.Web.Controls
{
	public partial class ContactsContent : iPhOwaControl
	{
		/// <summary>
		/// Load event.
		/// </summary>
		protected void Page_Load(object sender, EventArgs e)
		{
			Folder currentFolder = FolderManager.Get(Path, OwaSession);

			if(currentFolder != null)
			{
				List<Contact> notes = new List<Contact>(ContactManager.GetList(Path, OwaSession));

				notes = notes.FindAll(delegate(Contact p)
				                      	{
				                      		return !string.IsNullOrEmpty(p.MobilePhone) || !string.IsNullOrEmpty(p.WorkPhone);
				                      	});

				notes.Sort(delegate(Contact x, Contact y)
				           	{
				           		string xVal = x.IsCompany ? x.Company : x.DisplayName;
				           		string yVal = y.IsCompany ? y.Company : y.DisplayName;

								return string.Compare(xVal, yVal, StringComparison.CurrentCulture);
				           	});

				if(notes.Count > 0)
				{
					notesList.DataSource = notes;
					notesList.DataBind();
				}
				else
				{
					notesList.Visible = false;
					noMessagesPanel.Visible = true;
				}
			}
		}
	}
}